package main.java.design.memento;

import javax.swing.text.Caret;

/**
 * <p>
 *     备忘录模式
 * </p>
 *
 * @author : wangdejian
 * @version 1.0
 * @date : 2020/6/25 19:24
 */
public class Client {
    public static void main(String[] args) {

        System.out.println("*******用户初始信息********************");
        UserOriginator userOriginator = new UserOriginator();
        userOriginator.setUsername("lisi");
        userOriginator.setPasswd("654321");
        userOriginator.show();

        //备忘录存储发起人对象内部状态
        Caretaker caretaker = new Caretaker();
        caretaker.setMemento(userOriginator.createMemento());

        // lisi修改为张三,654321修改为123456
        userOriginator.setUsername("zhangsan");
        userOriginator.setPasswd("123456");
        userOriginator.show();


        // 恢复状态
        userOriginator.restoreMemento(caretaker.getMemento());
        userOriginator.show();
    }
}
